<?php
require_once '../ptnhuan-web1/libraries/utilites/functions.php';
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating1 = NULL;
$rating2 = NULL;
?>
<link rel="stylesheet" type="text/css" href="public/css/style.css">
<form method="POST">
    From : <input type="text" name="rating1">
    To :   <input type="text" name="rating2">
    <input type="submit" name="submit" value="Search">
</form>

<?php if (isset($_POST['submit'])): ?>
    <?php $rating1 = (double) $_POST['rating1']; ?>
    <?php $rating2 = (double) $_POST['rating2']; ?>
<?php endif; ?>

<?php foreach ($films as $item): ?>
    <?php $item = trim($item);//item:tung dong
    if (!empty($item)):?>
    <?php  //empty:rong  
    $film = explode(";", $item);//explode:tach ra thanh tung mang
  
    $img = trim($film[1],"\t\n\r");
    ?>
 <?php if (isset($film[2]) && (isset($film[3]))): ?> 



    <?php if (empty($rating1) && empty($rating2)): ?>
           
            <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'> 
            <?php echo $film[2] ?>
            <?php echo $film[3] ?>
             <a href="file_Edit.php?if=<?php echo $film[0]?>">  Edit</a>
            <br>
        <?php else: ?>
            <?php if (($rating1 <= (double) $film[3] ) && ((double) $film[3] <= $rating2 )): ?>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'> 
                <?php echo $film[2] ?>
                <?php if (!empty($film[3])) echo $film[3] ?>
                <a href="file_Edit.php?if=<?php echo $film[0]?>">  Edit</a>
                <br>
            <?php endif; ?>
               
        <?php endif; ?>
    <?php endif; ?>
    <?php endif;?>
<?php endforeach; ?> 
               

